<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/>
  <title>AR故事</title>

  <script src="./js/aframe-master.min.js"></script>
  <script src="./js/aframe-ar-nft.js"></script>

  <script src="https://cdn.bootcss.com/eruda/1.5.8/eruda.min.js"></script>
  <script>
    eruda.init();
    console.log('控制台打印信息');
  </script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .arjs-loader {
      height: 100%;
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background-color: rgba(0, 0, 0, 0.8);
      z-index: 9999;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .arjs-loader div {
      text-align: center;
      font-size: 1.25em;
      color: white;
    }

    /* 弹出跳转 */
    #tanchu {
      display: none;
      width: 200px;
      height: 100px;
      text-align: center;
      background-color: #999;
      border: 1px solid #000;
      border-radius: 10px;
      position: fixed;
      left: 50%;
      top: 50%;
      transform: translateX(-50%) translateY(-50%);
    }

    .tanchu_title {
      line-height: 40px;
    }

    .tanchu_btn {}
  </style>
  <script>

    let audio = null;
    // 页面加载完毕
    window.onload = function () {
      audio = document.getElementById("myAudio");
      // btn 按钮 点击跳转百度
      document.getElementById('btn').onclick = function () {
        // 跳转到百度
        window.location.href = 'https://www.baidu.com/'
      }
    }

    // 注册markerhandler组件
    // 该组件中注册了，当场景中检测到图像时触发的事件
    AFRAME.registerComponent('markerhandler', {
      init: function () {
        this.el.sceneEl.addEventListener('markerFound', () => {
          // alert('识别成功!')
          console.log('识别成功!')
          document.getElementById('tanchu').style.display = 'block';
          audio.play();
        });
        this.el.addEventListener("markerLost", () => {
          console.log("识别不到了");
          document.getElementById('tanchu').style.display = "none";
          audio.pause();
        })
      }
    });


  </script>
</head>

<body style="margin : 0px; overflow: hidden;">
  <div class="arjs-loader">
    <div>加载中</div>
  </div>
  <a-scene>
    <a-nft markerhandler type="nft" url="arTrack/feature/mubiao/mubiao"></a-nft>
  </a-scene>

  <div id="tanchu">
    <p class="tanchu_title">识别到目标特征</p>
    <button class="tanchu_btn" id="btn">跳转百度</button>
  </div>


  <audio id="myAudio" controls>
    <source src="./yinyue.mp3" type="audio/mpeg">
    您的浏览器不支持播放音频。
  </audio>
</body>

</html>